<template>
	<view class="page">
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" :class="{'action':OrderType==null}" @click="onOrderTab(null)">
				<text>售后申请</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==1}" @click="onOrderTab(1)">
				<text>处理中</text>
				<text class="line"></text>
			</view>
			<!-- <view class="tab" :class="{'action':OrderType==2}" @click="onOrderTab(2)">
				<text>售后评价</text>
				<text class="line"></text>
			</view> -->
			<view class="tab" :class="{'action':OrderType==2}" @click="onOrderTab(2)">
				<text>已退款</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单搜索 -->
		<view class="order-search">
			<view class="search">
				<text class="iconfont icon-fadajing"></text>
				<input type="text" placeholder="商品名称/商品编号/订单号/序列号">
			</view>
			<view class="filtrate" @click="isFiltrate = true">
				<text>筛选</text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="list" v-for="el in goodsList">
				<view class="order-number">
					<view class="number">
						<text>单号：{{el.order_sn}}</text>
					</view>
					<!-- <view class="type">
						<image src="/static/sale_th.png" mode=""></image>
						<text>{{el.statusTxt}}</text>
					</view> -->
				</view>
				<view class="goods-list">
					<view class="list">
						<view class="thumb">
							<image :src="el.img_list[0]"  mode=""></image>
						</view>
						<view class="item">
							<view class="title">
								<text class="two-omit">{{el.goodsName}}</text>
							</view>
							<view class="num">
								<text>数量：{{el.goods_num}} </text>
							</view>
						</view>
					</view>
				</view>
				<view class="order-status" v-if="OrderType == 1">
					<text>审核中</text>
					<text>{{el.retreatInfo.ctime}}</text>
				</view>
				<view class="order-status" v-if="OrderType == 2">
					<text>已退款</text>
					<text>{{el.retreatInfo.ctime}}</text>
				</view>
				<!-- el.isretreat === 1 && -->
				<view class="order-btn" @click="retreatOrder(el.id)" v-if="el.isretreat === 1 &&  !OrderType">
					<text class="action">申请退款</text>
				</view>
				<view class="order-btn" @click="cancnelretreatOrder(el.id)"v-if="el.status == 6 && OrderType==1">
					<text class="action">取消申请</text>
				</view>
			</view>
		</view>
		<!-- 筛选弹窗 -->
		<view class="filtrate-win" @click="isFiltrate = false">
			<view class="cu-modal drawer-modal justify-end" :class="{'show':isFiltrate}">
				<view class="cu-dialog basis-lg">
					<view class="order-time">
						<view class="title">
							<text>下单时间</text>
						</view>
						<view class="time-list">
							<view class="list action">
								<text>全部</text>
							</view>
							<view class="list">
								<text>一个月内</text>
							</view>
							<view class="list">
								<text>一个月至三个月</text>
							</view>
							<view class="list">
								<text>三个月六个月</text>
							</view>
							<view class="list">
								<text>六个月至一年</text>
							</view>
							<view class="list">
								<text>一年以上</text>
							</view>
						</view>
					</view>
					<view class="footer-btn">
						<view class="btn" @click="isFiltrate = false">
							<text>重置</text>
						</view>
						<view class="btn action" @click="isFiltrate = false">
							<text>确定</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getRetreatOrderList,
		cancelRetreatOrder,
		retreatOrder
	} from '@/config/api.js';
	export default {
		data() {
			return {
				
				queryList: {
					page: 1,
					limit:20,
					status: null,
					type: null
				},
				OrderType: null,
				isFiltrate: false,
				goodsList: [],
			};
		},
		onLoad(params) {
			getRetreatOrderList(this.queryList).then(res => {
				this.goodsList = res.data;
			})
		},
		methods: {
			cancnelretreatOrder(id){
				const _this = this;
				uni.showModal({
					title: '确认取消申请？',
					success: function(res) {
						if (res.confirm) {
							cancelRetreatOrder({
								id: id
							}).then(res => {
				
							})
						}
					}
				});
			},
			retreatOrder(id){
				const _this = this;
				uni.showModal({
					title: '请填退款原因',
					editable: true,
					placeholderText: '请填退款原因',
					success: function(res) {
						if (res.confirm) {
							retreatOrder({
								id: id,
								content: res.content
							}).then(res => {
				
							})
						}
					}
				});
			},
			/**
			 * 订单tab切换状态
			 * @param {Number} type
			 */
			onOrderTab(type) {
				this.OrderType = type;
				this.queryList.type = type;
				this.queryList.status = null;
				if(type){
					this.queryList.status = 6;
				}
				
				getRetreatOrderList(this.queryList).then(res => {
					this.goodsList = res.data;
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'AfterSalesOrder.scss';
</style>